﻿using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System8Equations;
using Microsoft.Silverlight.Testing;

namespace t_System8Equations
{
    [TestClass]
    public class t_S8TextParser
    {
        [TestMethod]
        public void TestCreation()
        {
            var s = new S8TextParser();
        }

        [TestMethod]
        public void TestEmptyParse()
        {
            var s = new S8TextParser();
            var s8 = new System8Equations.S8Equations();

            s8.n.Bottom = 100;
            s8.p.Bottom = 100;
            s8.n1.Bottom = 90;
            s8.n2.Bottom = 90;
            s8.p1.Bottom = 90;
            s8.p2.Bottom = 90;
            s8.n12.Bottom = 80;
            s8.p12.Bottom = 80;

            var text = "";
            s.Parse(s8, text);

            Assert.AreEqual(0, s8.n.Total, "s8.n is not zero");
            Assert.AreEqual(0, s8.p.Total, "s8.p is not zero");
            Assert.AreEqual(0, s8.n1.Total, "s8.n1 is not zero");
            Assert.AreEqual(0, s8.p1.Total, "s8.p1 is not zero");
            Assert.AreEqual(0, s8.n2.Total, "s8.n2 is not zero");
            Assert.AreEqual(0, s8.p2.Total, "s8.p2 is not zero");
            Assert.AreEqual(0, s8.n12.Total, "s8.n12 is not zero");
            Assert.AreEqual(0, s8.p12.Total, "s8.p12 is not zero");
        }

        [TestMethod]
        public void TestStandaloneOutput()
        {
            var text = "n: b=14814 c=11849 l=667\n p: b=7623 c=6083 l=349\n n1: b=6466 c=10001 l=602\n p1: b=3246 c=5131 l=314\n n2: b=11818 c=5418 l=472\n p2: b=6108 c=2848 l=243\n n12: b=5110 c=4534 l=421\n p12: b=2572 c=2390 l=216";

            var s = new S8TextParser();
            var s8 = new System8Equations.S8Equations();

            s.Parse(s8, text);

            Assert.AreEqual(14814, s8.n.Bottom, "n.bottom is wrong");
            Assert.AreEqual(11849, s8.n.Charm, "n.charm is wrong");
            Assert.AreEqual(667, s8.n.Light, "n.light is wrong");

            Assert.AreEqual(7623, s8.p.Bottom, "p.bottom is wrong");
            Assert.AreEqual(6083, s8.p.Charm, "p.charm is wrong");
            Assert.AreEqual(349, s8.p.Light, "p.light is wrong");

            Assert.AreEqual(6466, s8.n1.Bottom, "n1.bottom is wrong");
            Assert.AreEqual(10001, s8.n1.Charm, "n1.charm is wrong");
            Assert.AreEqual(602, s8.n1.Light, "n1.light is wrong");

            Assert.AreEqual(3246, s8.p1.Bottom, "p1.bottom is wrong");
            Assert.AreEqual(5131, s8.p1.Charm, "p1.charm is wrong");
            Assert.AreEqual(314, s8.p1.Light, "p1.light is wrong");

            Assert.AreEqual(11818, s8.n2.Bottom, "n2.bottom is wrong");
            Assert.AreEqual(5418, s8.n2.Charm, "n2.charm is wrong");
            Assert.AreEqual(472, s8.n2.Light, "n2.light is wrong");

            Assert.AreEqual(6108, s8.p2.Bottom, "p2.bottom is wrong");
            Assert.AreEqual(2848, s8.p2.Charm, "p2.charm is wrong");
            Assert.AreEqual(243, (int)s8.p2.Light, "p2.light is wrong");

            Assert.AreEqual(5110, s8.n12.Bottom, "n12.bottom is wrong");
            Assert.AreEqual(4534, s8.n12.Charm, "n12.charm is wrong");
            Assert.AreEqual(421, s8.n12.Light, "n12.light is wrong");

            Assert.AreEqual(2572, s8.p12.Bottom, "p12.bottom is wrong");
            Assert.AreEqual(2390, s8.p12.Charm, "p12.charm is wrong");
            Assert.AreEqual(216, s8.p12.Light, "p12.light is wrong");
        }

        [TestMethod]
        public void TestWithFullReturnsInIt()
        {
            ///
            /// Cut/Paste code is messier...
            /// 

            var text = "\t  n: b=14814 c=11849 l=667\r\n\t  p: b=7623 c=6083 l=349\r\n\t  n1: b=6466 c=10001 l=602\r\n\t  p1: b=3246 c=5131 l=314\r\n\t  n2: b=11818 c=5418 l=472\r\n\t  p2: b=6108 c=2848 l=243\r\n\t  n12: b=5110 c=4534 l=421\r\n\t  p12: b=2572 c=2390 l=216\r\n";

            var s = new S8TextParser();
            var s8 = new System8Equations.S8Equations();

            s.Parse(s8, text);

            Assert.AreEqual(14814, s8.n.Bottom, "n.bottom is wrong");
        }
    }
}